import matplotlib.pyplot as plt
import numpy as np 
import math

# 坐标旋转
# 绕pointx,pointy逆时针旋转
def Nrotate(angle,valuex,valuey,pointx,pointy):
  angle = math.radians(angle) #角度
  valuex = np.array(valuex)
  valuey = np.array(valuey)
  nRotatex = (valuex-pointx)*math.cos(angle) - (valuey-pointy)*math.sin(angle) + pointx
  nRotatey = (valuex-pointx)*math.sin(angle) + (valuey-pointy)*math.cos(angle) + pointy
  return nRotatex, nRotatey
# 绕pointx,pointy顺时针旋转
def Srotate(angle,valuex,valuey,pointx,pointy):
  angle = math.radians(angle) #角度
  valuex = np.array(valuex)
  valuey = np.array(valuey)
  sRotatex = (valuex-pointx)*math.cos(angle) + (valuey-pointy)*math.sin(angle) + pointx
  sRotatey = (valuey-pointy)*math.cos(angle) - (valuex-pointx)*math.sin(angle) + pointy
  return sRotatex,sRotatey

#角度计算
def Angle(x_value,y_value):
    """     
        直线与X轴的夹角，坐标：A(0,0) B(2,4)
        x_value = [0,2] #x坐标集
        y_value = [0,4] #y坐标集 
    """
    dx1 = x_value[1] - x_value[0]
    dy1 = y_value[1] - y_value[0]
    angle1 = math.atan2(dy1, dx1)
    angle1 = int(angle1 * 180/math.pi)
    
    return angle1

X = [0,2,4,6,8]
Y = [0,0,4,2,6]
X = np.array(X)
Y = np.array(Y)

plt.plot(0, 0, 'om')  # 绘制紫红色的圆形的点
plt.plot(X,Y,color='blue',linewidth=1.0,linestyle='-')  # 绘制

#坐标移动
X1=X-2 #向量减法（向量移动）
Y1=Y
print(X1)
plt.plot(X1,Y1,color='red',linewidth=1.0,linestyle='-')  # 绘制

#角度计算
#直线与X轴的夹角，坐标：A(0,0) B(2,4)
x_value = [0,2] #x坐标集
y_value = [0,4] #y坐标集
agl=Angle(x_value,y_value)
print(agl)

#坐标旋转
Pointx ,Pointy = Srotate(agl,X1,Y1,0,0)
plt.plot(Pointx,Pointy,color='black',linewidth=1.0,linestyle='-')  # 绘制紫红色的圆形的点

plt.show()